package edu.sjb_beta1.thread;

import edu.sjb_beta1.characters.Mario;
import edu.sjb_beta1.gui.GUI;
import edu.sjb_beta1.map.LogicMapElement;
import edu.sjb_beta1.map.MapBrick;

public class MarioRightUpdaterThread extends Thread {
    private Mario mario;

    public MarioRightUpdaterThread(Mario m) {
        mario = m;
    }

    public void run() {
        while (mario.isAlive()) {
            try {
                double marioX = GUI.mario.getPositionX();
                double marioY = GUI.mario.getPositionY();
                int X = (int) marioX / 32;
                int Y = (int) marioY / 32;
                LogicMapElement rightMario = GUI.levelMap.getElementAt(X + 1, Y
                        + 1).getLogicElement();
                if (!rightMario.getName().equals(MapBrick.ELEMENT_NAME)) {
                    mario.setLocation(mario.getLocation().x + 8,
                            mario.getLocation().y);
                    Thread.sleep(100);
                }
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}